<script setup>
import GetBack from '@/components/GetBack.vue';
import Vrouter from "@/router"
import { addlogin, code } from '@/api/login/login.js'
import { inject } from 'vue'
const router = Vrouter;

import { ref } from 'vue'
import { MYURL as URL } from '@/utils/express/express.js'
const input_passwd = ref(`${URL}/public/icon/text.png`)
const success_message = inject('change_message_state')
let real_code = null
const changeimage = () => {
    input_passwd.value = `${URL}/public/icon/passwd.png`
}
const changepasswd = () => {
    input_passwd.value = `${URL}/public/icon/text.png`
}
const go_login = () => {
    router.replace('/login')
}
const addlogiin_btn = () => {
    const input = document.querySelectorAll('input')
    let input_value = []
    for (let i = 0; i < input.length; i++) {
        input_value.push(input[i].value)
    }
    let data = { account: input_value[0], username: input_value[1], password: input_value[2], repassword: input_value[3], code: input_value[4].toLowerCase(), code_id: real_code }
    addlogin(data).then((res) => {
        if (res.data.status === 1) {
            success_message(res.data.message)
        } else {
            success_message(res.data.message)
            router.replace('login')
        }
    })
    get_code()
}
let my_code = ref(null)
const get_code = () => {
    code().then((res) => {
        my_code.value.innerHTML = res.data.data
        real_code = res.data.code_id
    })
}
get_code()
</script>

<template>
    <div class="addlogin-success"></div>
    <GetBack>注册</GetBack>
    <div class="back-ground"></div>
    <img class="input_passwd" :src="input_passwd">
    <div class="my-input">
        <div>
            <p>账号</p>
            <input type="text" placeholder="请输入您想要注册的账号">
        </div>
        <div>
            <p>昵称</p>
            <input type="text" placeholder="请输入您的昵称">
        </div>
        <div>
            <p>密码</p>
            <input @blur="changepasswd" @focus="changeimage" type="password" placeholder="请输入密码">
        </div>
        <div>
            <p>确认密码</p>
            <input @blur="changepasswd" @focus="changeimage" type="password" placeholder="请再次输入密码">
        </div>
        <div>
            <p>验证码</p>
            <div>
                <input @blur="changepasswd" type="text" placeholder="请输入验证码">
                <div @click="get_code" ref="my_code"></div>
            </div>
        </div>
    </div>
    <div class="login-btn">
        <p @click="go_login">返回登录</p>
        <p @click="addlogiin_btn">注册</p>
    </div>
</template>

<style scoped lang="less">
.back-ground {
    position: fixed;
    top: 0;
    left: 0;
    background-color: #f2f3f5;
    width: 100vw;
    height: 100vh;
    z-index: -1;
}

input {
    border: none;
    outline: none;
}

.input_passwd {
    width: 100%;
}

.my-input {
    margin-top: -10px;
    background-color: white;
    padding: 0px 10px;
    font-size: 14px;

    >div {
        padding: 20px 0;
        display: flex;
        align-items: center;
        gap: 30px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.082);

        p {
            width: 20%;
            text-align: end;
        }

        input {
            font-size: 14px;
        }

        div {
            display: flex;
            align-items: center;
        }

    }

    div:last-child {
        border: none;
    }

}

.login-btn {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 3%;

    p {
        width: 45%;
        text-align: center;
    }

    p:nth-child(1) {
        padding: 10px 0;
        border-radius: 5px;
        border: 1px #ef85a6 solid;
        color: #ef85a6;
    }

    p:nth-child(2) {
        padding: 10px 0;
        border-radius: 5px;
        background-color: #ef85a6;
        color: white;
    }
}
</style>
